package org.jsp.web;

import org.jsp.pojo.Brand;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/jstlServletDemo")
public class JstlServletDemo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("jstlServletDemo_doGet?");
        //准备数据
        List<Brand> brands = new ArrayList<Brand>();
        brands.add(new Brand(1, "三只", "松鼠", 100, "呵呵", 1));
        brands.add(new Brand(2, "优衣库", "优衣库", 200, "优衣库，呵呵", 0));
        brands.add(new Brand(3, "小米", "有限公司", 500, "小米", 1));
        //存储到request域中
        req.setAttribute("brands", brands);
        //req.setAttribute("status", 1);

        //转发到el-demo.jsp
        req.getRequestDispatcher("/jstl.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("jstlServletDemo_doPost?");
        this.doGet(req, resp);
    }
}
